import request from '../utils/request';
import { translateObj } from '../utils/translateObj';
import { authToken, apiToken } from '../utils/encryption';
let baseURL = '';

// 联通第三方平台权限验证接口

export function userAuth(data={}){
    return request.get('/admin/sso/codeLoginAc', { data, noprefix:true }).catch(err=>console.log(err));
}

export function loginOut(data={}){
    return request.get('/admin/sso/logout', { data, noprefix:true }).catch(err=>console.log(err));
}

export function login(data = {}){
    return request.post('/admin/user/bmLogin', { data, baseURL }).catch(err=>console.log(err)); 
}

// 通用的导出excel接口
export function createExcel(col, row){
    let token = apiToken();
    let config = window.g;
    let url = `http://${config.apiHost}/api/export/createexcel?col=${JSON.stringify(col)}&row=${JSON.stringify(row)}&token=${token}`;
    window.location.href = url;

}

// 第三方地图geoJson数据的请求接口
export function getGeoJson(data = {}){
    let token = apiToken();
    data.token = token;
    let str = translateObj(data);
    return request('/index/geojson', { 
        method:'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        body:str
        }); 
}
